package com.songshuai.sales.client.controller;

import com.songshuai.sales.client.service.CommonService;
import com.songshuai.webapi.baseapi.dto.feign.response.DictionaryDto;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @Author: lhx
 * @Date: 2019/3/26 13:26
 */
@Api("公共类")
@RestController
@RequestMapping("/api/sales/common/")
public class CommonController {


    @Autowired
    private CommonService commonService;


    /**
     * 根据字典类型查询字典
     * @param type
     * @return
     */
    @GetMapping("queryDictionariesByType")
    public CompletableFuture<QueryResponse<List<DictionaryDto>>> queryDictionariesByType(@RequestParam("type")Integer type){
        return CompletableFuture.supplyAsync(() -> commonService.queryDictionariesByType(type));
    }


    /**
     * 根据id查询字典详情
     * @param id
     * @return
     */
    @GetMapping("queryDictionaryDetail")
    public CompletableFuture<QueryResponse<DictionaryDto>> queryDictionaryDetail(@RequestParam("id")Integer id){
        return CompletableFuture.supplyAsync(() -> commonService.queryDictionaryDetail(id));
    }


    /**
     * 图片上传（七牛云）
     * @param file
     * @return
     */
    @PostMapping("uploadPicture")
    public CompletableFuture<QueryResponse> uploadPicture(@RequestParam("file") MultipartFile file){
        return CompletableFuture.supplyAsync(() -> commonService.uploadPicture(file));
    }


    /**
     * 图片上传（阿里云）
     * @param file
     * @return
     */
    @PostMapping("uploadPictureOss")
    public CompletableFuture<QueryResponse> uploadPictureOss(@RequestParam("file") MultipartFile file){
        return CompletableFuture.supplyAsync(() -> commonService.uploadPictureOss(file));
    }


}
